import { defHttp } from '/@/utils/http/axios';
import { isArray } from '/@/utils/is';
async function getEnhanceJsByCode(code, type, params) {
  let { success, data } = await defHttp.get(
    {
      url: '/api-online/online/cgform/head/enhanceJs/' + code,
      params: Object.assign({}, params, {
        type,
      }),
    },
    { isTransformResponse: false }
  );
  if (!success) {
    data = { cgJs: '' };
  }
  return data;
}
const saveEnhanceJs = (code, params, isUpdate) => {
  const url = `${'/api-online/online/cgform/head/enhanceJs/'}${code}`;
  if (isUpdate) {
    return defHttp.put({ url, params }, { successMessageMode: 'none' });
  } else {
    return defHttp.post({ url, params }, { successMessageMode: 'none' });
  }
};
async function getEnhanceJavaByCode(code, params) {
  const btnRes = await defHttp.get({ url: '/api-online/online/cgform/head/enhanceButton/' + code }, { isTransformResponse: false });
  let btnList = [];
  if (btnRes.success && isArray(btnRes.data)) {
    btnList = btnRes.data.filter((item) => item.optType == 'action');
  }
  const path = `${'/api-online/online/cgform/head/enhanceJava'}/${code}`;
  const dataSource = await defHttp.get({ url: path, params });
  return { btnList, dataSource };
}
function doEnhanceJavaBatchDelete(idList) {
  return defHttp.delete(
    {
      url: '/api-online/online/cgform/head/deleteBatchEnhanceJava',
      params: {
        ids: idList.join(','),
      },
    },
    { joinParamsToUrl: true }
  );
}
const saveEnhanceJava = (code, params, isUpdate) => {
  const url = `${'/api-online/online/cgform/head/enhanceJava'}/${code}`;
  if (isUpdate) {
    return defHttp.put({ url, params });
  } else {
    return defHttp.post({ url, params });
  }
};
async function getEnhanceSqlByCode(code, params) {
  const btnRes = await defHttp.get({ url: '/api-online/online/cgform/head/enhanceButton/' + code }, { isTransformResponse: false });
  let btnList = [];
  if (btnRes.success && isArray(btnRes.data)) {
    btnList = btnRes.data.filter((item) => item.optType == 'action');
  }
  const path = `${'/api-online/online/cgform/head/enhanceSql'}/${code}`;
  const dataSource = await defHttp.get({ url: path, params });
  return { btnList, dataSource };
}
function doEnhanceSqlBatchDelete(idList) {
  return defHttp.delete(
    {
      url: '/api-online/online/cgform/head/deletebatchEnhanceSql',
      params: {
        ids: idList.join(','),
      },
    },
    { joinParamsToUrl: true }
  );
}
const saveEnhanceSql = (code, params, isUpdate) => {
  const url = `${'/api-online/online/cgform/head/enhanceSql'}/${code}`;
  if (isUpdate) {
    return defHttp.put({ url, params });
  } else {
    return defHttp.post({ url, params });
  }
};
export {
  getEnhanceJavaByCode,
  saveEnhanceJava,
  getEnhanceSqlByCode,
  doEnhanceJavaBatchDelete,
  saveEnhanceSql,
  doEnhanceSqlBatchDelete,
  getEnhanceJsByCode,
  saveEnhanceJs,
};
